﻿using System;
using System.Collections.Generic;

using Roslyn.Compilers.CSharp;

namespace ScriptXCompiler
{
    public class TypeWalker : SyntaxWalker
    {
        private SemanticModel _model;
        private SyntaxTreeRelationship _relation;
        public TypeWalker(SemanticModel model, SyntaxTreeRelationship relation)
        {
            _model = model;
            _relation = relation;
        }

        protected override void VisitClassDeclaration(ClassDeclarationSyntax node)
        {
            var type = _model.GetDeclaredSymbol(node);
            _relation.AddProvide(type);
            if (node.BaseListOpt != null)
            {
                foreach (var b in node.BaseListOpt.Types)
                {
                    var bType = _model.GetSemanticInfo(b);
                    _relation.AddDependency(bType.Type);
                }
            }
        }

        protected override void VisitEnumDeclaration(EnumDeclarationSyntax node)
        {
            var type = _model.GetDeclaredSymbol(node);
            _relation.AddProvide(type);
        }

        protected override void VisitInterfaceDeclaration(InterfaceDeclarationSyntax node)
        {
            var type = _model.GetDeclaredSymbol(node);
            _relation.AddProvide(type);
        }
    }
}
